
component output="false" extends="AbsService" accessors="true" {

	// Delegate
	property name="CommentDelegate" type="it.millemultimedia.easyBlog.delegate.CommentDelegate";

	public it.millemultimedia.easyBlog.service.CommentService function init(){
		
		return this;
	}
	
	public it.millemultimedia.easyBlog.validator.CommentValidator function getValidator(){
		
		return getCommentDelegate().getValidator();
	}
	
	public it.millemultimedia.easyBlog.model.Comment function new(){
		
		return getCommentDelegate().createInstance();
	}
	
	public it.millemultimedia.easyBlog.model.Comment function getComment( required Any Comment ){
		
		return getCommentDelegate().read( arguments.Comment );
	}
	
	public it.millemultimedia.easyBlog.model.Comment[] function getComments( required Any Comment ){
		
		return getCommentDelegate().list( arguments.Comment );
	}
	
	public it.millemultimedia.easyBlog.model.Comment[] function getCommentsPaged( required Any Comment, required Numeric start, Numeric maxrow=10 ){
		
		return getCommentDelegate().list( arguments.Comment, arguments.start, arguments.maxrow );
	}
	
	public boolean function commentExists( required Any Comment ){
		var result = getCommentDelegate().list( arguments.Comment );
		
		return arrayLen( result ) gt 0;
	}
	
	public void function saveComment( required Any Comment ){
	
		transaction{
		
			try{
				
				
				if( arguments.Comment.getidComment()  eq 0 ){
				
					this.createComment( arguments.Comment );
				
				}else if( arguments.Comment.getIdComment() gt 0 ){
				
					this.updateComment( arguments.Comment );
				
				}else{
				
					throw( message="Comment id property have undefined value." );
				
				}
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function createComment( required Any Comment ){
	
		transaction{
		
			try{
			
				getCommentDelegate().create( arguments.Comment );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function updateComment( required Any Comment ){
	
		transaction{
		
			try{
			
				getCommentDelegate().update( arguments.Comment );
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
			
			}
		
		}
		
	}
	
	public void function deleteComment( required Any Comment ){
	
		transaction{
		
			try{
			
				getCommentDelegate().delete( arguments.Comment );
				
			
			}catch( except Any ){
			
				transaction action="rollback";
				
				throw( except.message );
							
			}
			
		}
		
	}
	
}
